package com.bwie.redkids.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bwie.redkids.R;
import com.bwie.redkids.bean.NewProductBean.MyProductListBean;
import com.lidroid.xutils.BitmapUtils;

public class NewProductAdapter extends BaseAdapter {

	private ArrayList<MyProductListBean> arrayList;
	private Context context;

	public NewProductAdapter(Context context,
			ArrayList<MyProductListBean> arrayList) {
		this.context = context;
		this.arrayList = arrayList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arrayList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.flash_sale_item, null);
			holder = new ViewHolder();
			holder.home1_img = (ImageView) convertView
					.findViewById(R.id.home1_img);
			holder.home1_title = (TextView) convertView
					.findViewById(R.id.home1_title);
			holder.home1_old_price = (TextView) convertView
					.findViewById(R.id.home1_old_price);
			holder.home1_price = (TextView) convertView
					.findViewById(R.id.home1_price);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		BitmapUtils bitmapUtils = new BitmapUtils(context);
		bitmapUtils.display(holder.home1_img, arrayList.get(position).getPic());
		holder.home1_title.setText(arrayList.get(position).getName());
		holder.home1_old_price.setText("原价"
				+ arrayList.get(position).getMarketprice());
		holder.home1_old_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
		holder.home1_price.setText("现价" + arrayList.get(position).getPrice());
		return convertView;
	}

	class ViewHolder {
		ImageView home1_img;
		TextView home1_title;
		TextView home1_old_price;
		TextView home1_price;
	}
}
